#include <stdio.h>  
#include <stdlib.h>
#include <unistd.h>
#include <termio.h>  
static struct termios tty;  
enum Key{None, KeyESCClick, KeyEnterClick,  
	KeyUpClick, KeyDownClick,  
	KeyLeftClick, KeyRightClick};  
void set_key();  
void reset_key();  
enum Key getKey();  

int main(int argc, char *argv[])  
{  
	scanf("%s",NULL);
	char a;
	set_key();  
	while (1) {
		a = getchar();
		printf("%d", a);
	}
	/*
	while(1)  
	{  
		a=getch();  
		switch(a)  
		{     
			case KeyESCClick:  
				printf("esc/n");  
				reset_key();  
				return 0;  
			case KeyEnterClick:  
				printf("enter/n");  
				break;  
			case KeyUpClick:  
				printf("up/n");  
				break;  
			case KeyDownClick:  
				printf("down/n");  
				break;  
			case KeyLeftClick:  
				printf("left/n");  
				break;  
			case KeyRightClick:  
				printf("right/n");  
				break;  
			default:  
				break;  
		}  
	}  
	*/
	reset_key();  
	return 0;  
}  
void set_key()  
{  
	struct termios new_tty;  
	tcgetattr(0,&tty);  
	new_tty=tty;  
	new_tty.c_lflag&=~(ICANON|ECHO|ISIG);  
	new_tty.c_cc[VTIME]=0;  
	new_tty.c_cc[VMIN]=1;  
	tcsetattr(0,TCSANOW,&new_tty);  
	return;  
}  
void reset_key()  
{  
	tcsetattr(0,TCSANOW,&tty);  
	return;  
}  
/*  
 *  修改了getch函数，由于上下左右方向键的字符编码特殊，所以在read中如果一次读取只有一个字符，那么就是普通字符， 
 *  如果是三个字符，那么就是方向键，再通过判断最后一个字符的内容就可以确定是方向键中的那一个。 
 *  */  
enum Key getKey()  
{  
	int i;  
	char ch[3];  
	while((i = read(0, ch, 3)) != -1)  
	{  
		printf("get char num: %d/n", i);  
		switch(i)  
		{  
			case 1:  
				switch(ch[0])  
				{  
					case 0x1b:  
						return KeyESCClick;  
					case 0x0a:  
						return KeyEnterClick;  
				}  
				break;  
			case 3:  
				switch(ch[2])  
				{  
					case 'A':  
						return KeyUpClick;  
					case 'B':  
						return KeyDownClick;  
					case 'C':  
						return KeyRightClick;  
					case 'D':  
						return KeyLeftClick;  
				}  
		}  
	}  
	return None;  
}  

